from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime
from sqlalchemy.sql import func
from sqlalchemy.dialects.postgresql import ARRAY, JSONB
from ..database import Base


class ModelConfig(Base):
    __tablename__ = 'models'

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)

    # 模型信息
    channel_id = Column(Integer, nullable=True)
    channel = Column(String(50), nullable=True)
    model = Column(String(50), nullable=False)

    # 请求参数
    temperature = Column(Float, server_default='1.0')
    max_tokens = Column(Integer, server_default='2048')
    top_p = Column(Float, server_default='1.0')
    presence_penalty = Column(Float, server_default='0.0')
    frequency_penalty = Column(Float, server_default='0.0')
    n = Column(Integer, server_default='1')
    stop = Column(ARRAY(String(100)), nullable=True)
    logit_bias = Column(JSONB, nullable=True)
    stream = Column(Boolean, server_default='false')
    response_format = Column(String(20), nullable=True)
    reasoning_effort = Column(String(20), nullable=True)

    # 元数据
    endpoint_url = Column(String(255), nullable=True)
    file_path = Column(String(255), nullable=True)
    api_key = Column(String(50), nullable=True)
    created_at = Column(DateTime(timezone=True), server_default=func.now())
